/**
 * 2010-2011 xiha.org
 */
package org.xiha.wiki.apps;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.xiha.web.DoInvoke;
import org.xiha.web.Param;
import org.xiha.wiki.database.AckView;
import org.xiha.wiki.database.BasicDatabase;
import org.xiha.wiki.domain.Ack;

/**
 * @author summer
 * 
 */
public class DoEdit {
    
    @DoInvoke(tt = "doEdit.vm")
    public Ack execute(@Param(name = "subject") String subject, @Param(name = "content") String content) {
        
        BasicDatabase db = new BasicDatabase("~/");
        db.openAck();
        
        AckView basicView = new AckView(db);
        
        Map<String, Ack> acks = basicView.getAckStoredMap();
        String[] s = StringUtils.split(content, "\r\n");
        
        List<String> l = new ArrayList<String>();
        
        for (int i = 0; i < s.length; i++) {
            l.add(s[i]);
        }
        
        Ack ack = new Ack(DigestUtils.md5Hex(subject), subject, l, null);
        
        acks.put(ack.getUniqueNo(), ack);
        
        db.closeAck();
        
        return ack;
    }
}
